package data;

import java.io.Serializable;
import java.util.Date;

/**
 * Data structure to hold Episode data.
 * @author Jen
 *
 */
public class Episode implements Serializable
{
	/**
	 * The serialnumber for Episode
	 */
	private static final long serialVersionUID = 01;

	/** the episode number (for the season it's a part of) */
	private int episodeNumber;
	
	/** the title of the episode */
	private String episodeTitle;
	
	/** the torrentURL */
	private String torrentURL = null;
	
	/** description of the episode */
	private String description = null;

	/** the date the episode aired */
	private Date airDate = null;

	/**
	 * Constructor
	 * @param epNum integer episode number
	 * @param epTitle string episode title
	 * @param torrentURL string torrent URL
	 * @param description string episode description
	 * @param airDate string the air date in Mon, 13 Jun 2011 03:00:28 -0500 form.
	 */
	public Episode(int epNum, String epTitle, String torrentURL, String description, Date airDate) 
	{
		this.episodeNumber = epNum;
		this.episodeTitle = epTitle;
		this.torrentURL = torrentURL;
		this.description = description;
		this.airDate = airDate;
	}
		
	/**
	 * get's the episode title
	 * @return String episode title
	 */
	public String getTitle()
	{
		return this.episodeTitle;
	}
	
	/**
	 * get's the episode number
	 * @return integer episode number
	 */
	public int getEpisodeNumber()
	{
		return this.episodeNumber;
	}
	
	/**
	 * get's the episode title
	 * @return string episode title
	 */
	public String getEpisodeTitle()
	{
		return this.episodeTitle;
	}

	/**
	 * set's the torrent URL
	 * @param torrentURL string episode's new url
	 */
	public void setTorrentURL(String torrentURL) 
	{
		this.torrentURL = torrentURL;
	}

	/**
	 * get's the torrent URL
	 * @return string torrent URL
	 */
	public String getTorrentURL() 
	{
		return torrentURL;
	}

	/**
	 * set's the description for the episode.
	 * @param description string the episodes new description.
	 */
	public void setDescription(String description) 
	{
		this.description = description;
	}
	
	/**
	 * get's the description from the episode
	 * @return string description 
	 */
	public String getDescription() 
	{
		return description;
	}

	/**
	 * set's the air date
	 * @param string airDate the episode's new air date.
	 */
	public void setAirDate(Date airDate) 
	{
		this.airDate = airDate;
	}

	/**
	 * the date the episode aired
	 * @return Date airdate
	 */
	public Date getAirDate() 
	{
		return this.airDate;
		//return (Date)airDate.clone();
	}
	
	/**
	 * Returns a string representation of the episode.
	 * @return String representation of the episode.
	 */
	public String toString()
	{
		String returnString="";
		
		returnString += "Episode: "		+this.getEpisodeNumber()+" ";
		returnString += "Title: "		+this.getEpisodeTitle()	+" ";
		returnString += "URLs: "+this.getTorrentURL()	+" ";
		returnString += "Description: "	+this.getDescription()	+" ";
		returnString += "Air Date: "	+this.getAirDate()		+" ";
		
		return returnString;
	}


	public boolean merge(Episode b) 
	{
		boolean returnBool = true;
		if(this.getTorrentURL() == null && b.getTorrentURL() != null)
		{
			this.setTorrentURL(b.getTorrentURL());
		}
		if(this.getDescription() == null && b.getDescription() != null)
		{
			this.setDescription(b.getDescription());
		}
		if(this.getAirDate() == null && b.getTorrentURL() != null)
		{
			this.setAirDate(b.getAirDate());
		}
		else
		{
			returnBool = false;
		}
		return returnBool;
	}

}
